package mn.more.foundation.convert;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author $Author: mikeliucc $
 * @version $Id: CollectionConverter.java 5 2008-09-01 12:08:42Z mikeliucc $
 */
public final class CollectionConverter {

	private CollectionConverter() { }

	public static String toString(Map map) { return toString(map, null); }

	public static String toString(Map map, String prependEachLine) {
		StringBuilder builder = new StringBuilder();
		Set keys = map.keySet();
		for (Object key : keys) {
			if (prependEachLine != null) { builder.append(prependEachLine); }
			builder.append(key).append("=");
			builder.append(map.get(key)).append("\n");
		}

		return builder.toString();
	}

	public static String toString(List list) { return toString(list, null); }

	public static String toString(List list, String prependEachLine) {
		StringBuilder builder = new StringBuilder();
		for (Object value : list) {
			if (prependEachLine != null) { builder.append(prependEachLine); }
			builder.append(value).append("\n");
		}

		return builder.toString();
	}
}
